package ui;

import java.awt.BorderLayout;
import java.awt.EventQueue;
import java.sql.SQLException;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JComboBox;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;

import bdd.Traitement;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

public class fenetreCharge extends JDialog {

	private JPanel contentPane;
	private JComboBox comboBox = new JComboBox();
	private Traitement traitement = new Traitement();
	private String scenario[] = new String[3];
	Fenetre fen;

	/**
	 * Create the frame.
	 * @throws SQLException 
	 */
	public fenetreCharge(Fenetre frame) throws SQLException {
		this.fen = frame;
		setResizable(false);
		this.setTitle("J-SIM Forest - Chargement");
		this.setLocationRelativeTo(null);
		setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		setBounds(100, 100, 295, 147);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		

		comboBox.setBounds(10, 49, 269, 20);
		contentPane.add(comboBox);
		
		JButton charger = new JButton("Charger");
		charger.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				try {
					if(comboBox.getSelectedItem()!=null){
						setScenario(traitement.chargerScenario(comboBox.getSelectedItem().toString()));
						fen.setTaille(scenario[0]);
						fen.setnbPas(scenario[1]);
						fen.setVitesse(scenario[2]);
						fen.setnewGrille(traitement.chargerCellule(comboBox.getSelectedItem().toString()));

					}
					else{
						dispose();
					}
				} catch (SQLException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				
				dispose();
			}
		});
		charger.setBounds(41, 80, 194, 23);
		contentPane.add(charger);
		
		JLabel lblChoississezUnScnario = new JLabel("Choisissez un sc\u00E9nario :");
		lblChoississezUnScnario.setBounds(10, 24, 153, 14);
		contentPane.add(lblChoississezUnScnario);
		this.setVisible(true);
		remplirComboBox();
	}
	
	void remplirComboBox() throws SQLException{
		 String scenario[]=traitement.remplirComboBox();
		 for (int i = 0; i < scenario.length; i++) {
			 comboBox.addItem(scenario[i]);
		}

	}

	public String[] getScenario() {
		return scenario;
	}

	public void setScenario(String scenario[]) {
		this.scenario = scenario;
	}
	
	
}
